package leetcode_100;

/**
 *@author 周杨
 *RemoveDuplicatesfromSortedArrayII_80 删除数组中重复的数 允许保留两次同一个数
 *describe: 利用count 只计算符合要求的数 将符合要求的数 放在nums[count]上 AC 65%
 *2018年5月14日 下午10:08:41
 */
public class RemoveDuplicatesfromSortedArrayII_80 {

	public static void main(String[] args) {
		RemoveDuplicatesfromSortedArrayII_80 test=new RemoveDuplicatesfromSortedArrayII_80();
		int nums[] =new int[] {1,2,2,2,3,3,5,6,6,6,6,7,7,7,8,8,9,9,9,9,10};
		int nums1[]=new int[] {1,2,2,2,2,4,4,5,5,5,6};
		int nums2[]=new int[] {0,0,1,1,1,1,2,3,3};
		int nums3[]=new int[] {-50,-50,-49,-48,-47,-47,-47,-46,-45,-43,-42,-41,-40,-40,-40,-40,-40,-39,-38,-38,-38,-38,-37};
		int nums4[]= {0,0,0,1};
		System.out.println(test.removeDuplicates(nums3));

	}
	
	public int removeDuplicates(int[] nums) {
		boolean flag=false;
		if(nums.length<=2)
			return nums.length;
		int count=1,now=nums[0];
		for(int i=1;i<nums.length;++i) {
			if(nums[i]==now) {
				if(!flag)
				{
					flag=true;
					nums[count]=now;
					++count;
				}
			}
			else {
				now=nums[i];
				flag=false;
				nums[count]=now;
				++count;
			}
		}
		return count;
    }

}
